<?php
namespace Model;
use Kuyuan\WqCore\Model\Model;

/**
 * 会员列表管理
 * Class MemberModel
 * @package Model
 */
class MemberModel extends Model
{
    protected $_fields = array(
        "id",
        "uniacid",
        "uid",
        "balance",
        "hint_more",
        "register_time"
    );

    // ----set---
    public function setRegisterTimeAttr()
    {
        return TIMESTAMP;
    }

    // ---get----
    public function getRegisterTimeAttr($_value)
    {
        if($_value) {
            return date("Y-m-d H:i:s",$_value);
        }
    }

    /**
     * 用户头像
     * @param $_value
     * @param $_data
     * @return mixed
     */
    public function getAvatarAttr($_value,$_data)
    {
        if(isset($_data["uid"])) {
            return W7McMembersModel::where("uid",$_data["uid"])
                ->cache(!KUYUAN_DEBUG)
                ->value("avatar");
        }
    }

    /**
     * 获取用户昵称
     * @param $_value
     * @param $_data
     * @return mixed
     */
    public function getNicknameAttr($_value,$_data)
    {
        if(isset($_data["uid"])) {
            return W7McMembersModel::where("uid",$_data["uid"])
                ->cache(!KUYUAN_DEBUG)
                ->value("nickname");
        }
    }

    /**
     * 用户发的红包数量
     * @param $_value
     * @param $_data
     * @return mixed
     */
    public function getRedNumberAttr($_value,$_data)
    {
        if(isset($_data["uid"])) {
            global $_W;
            return RedModel::where("uid",$_data["uid"])
                ->where("uniacid",$_W["account"]["uniacid"])
                ->where("status","!=",1)
                ->where("status","!=",6)
                ->where("status","!=",8)
                ->count();
        }
    }
}